<div class="layui-fluid nepadmin-pad0 nepadmin-mar0 list0 pay_set" id="list" lay-title="物联网管理">
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-body">
			  
			<div>
				<button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button>
				<button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>
			</div>
            <table class="layui-hide" id="list-table" lay-filter="list-table"></table>
			<script type="text/html" id="list-tableF">
			  <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|停用" lay-filter="list-tableF"
			   value="{{ d.status }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.status == '1' ? 'checked' : '' }}>
			</script>
			<div id="list-toolbar" style="display: none;">
				
			  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
			            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
			</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<script>
   //表格数据渲染
  var formurl='iot/iotform',formarea=['500px', '500px'];
  layui.use(['table','form'], function () {
	  var table = layui.table
	  ,form = layui.form
	  ,$ = layui.$;
	  layui.admin.initlist(table,'iot/list',195,[[
		{type:'checkbox',fixed:'left'}
        ,{field:'iot_id', title: 'ID', width:50}
        ,{field:'iot_name', title: '物联网名称', minWidth:100}
		,{field:'product_key', title: '公钥', minWidth:200}
		,{field:'product_secret', title: '私钥', minWidth:200}
		,{field:'status', title:'启用/停用', width:100, templet: '#list-tableF', unresize: true}
		,{field:'create_time', title: '创建时间', width:200}
		,{title:'操作', toolbar: '#list-toolbar',fixed:'right', width:150}
      ]])
	//监听表格表单操作
	form.on('switch(list-tableF)', function(obj){
	  var json = JSON.parse(decodeURIComponent($(this).data('json')));
	  json = table.clearCacheKey(json);
	  layui.admin.ajax('iot/update',{
		  status:json.status==1?2:1,
		  iot_id:json.iot_id
	  }).then(function(res){
		table.reload('list-table');
	  }).catch(function(res){});
	});
	
	//监听表格操作事件
	table.on('tool(list-table)', function(obj){
	  var data = obj.data;
	  //删除
	  if(obj.event === 'del'){
		layer.confirm('确定删除'+data.iot_name+'?', function(index){
		  layui.admin.delF(table,'iot/delete',{iot_id:data.iot_id});
		});
	  } else if(obj.event === 'edit'){//编辑
		layui.admin.pupF('编辑物联网',formarea,formurl,2,data)
	  }
	});
	//监听行双击事件
	/* table.on('rowDouble(list-table)', function(obj){
		//查看详情
		if($('.pay_set').length){
			layui.admin.pupF('支付详情',formarea,formurl,3,obj.data);
		}
	  
	}); */
	var active = {
	  //多行删除
	  batchdel:function(){
		  layui.admin.delsF(table,'iot/delete','iot_id')
	  }
	  //添加
	  ,add: function(othis){
		layui.admin.pupF('添加物联网',formarea,formurl,1,{})
	  }
	}; 
	//操作dom
	$('.layui-btn.layuiadmin-btn-list').on('click', function(){
	  var type = $(this).data('type');
	  active[type] ? active[type].call(this) : '';
	});
	
  });
</script>